package vmcs.utility;

import java.util.HashMap;
import java.util.Map;

import vmcs.entity.DrinksBrand;
import vmcs.entity.DrinksStoreItem;
import vmcs.entity.StoreItem;
import vmcs.factory.CloneableObjectEnum;
import vmcs.factory.ObjectRegistry;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */

public class DrinkPropertyLoader extends PropertyLoader {

  public DrinkPropertyLoader(String filen) {
    super(filen);
  }

 /* public DrinksStoreItem getItem(int idx){
    DrinksStoreItem   cit;

    DrinksBrand db = new DrinksBrand();
    String  item, itemv;

    item = new String("Name" + idx);
    itemv = getValue(item);

    db.setName(itemv);

    item = new String("Price" + idx);
    itemv = getValue(item);
    db.setPrice(Integer.parseInt(itemv));

    item = new String("Quantity" + idx);
    itemv = getValue(item);

    cit = new DrinksStoreItem(db, Integer.parseInt(itemv));

    return cit;
  }*/
  
  public StoreItem getItem(int idx) {
	    DrinksStoreItem   cit;
	    
	    Map<String,String> params=new HashMap<String, String>();
	    

	    DrinksBrand db = new DrinksBrand();
	    String  item = null, itemv = null;

	    item = new String("Name" + idx);
	    itemv = getValue(item);
	    params.put("name", itemv);

	    db.setName(itemv);

	    item = new String("Price" + idx);
	    itemv = getValue(item);
	    params.put("price", itemv);
            int price = Integer.parseInt(itemv);
            db.setPrice(price);
            
	    //DrinksBrand drink = (DrinksBrand)StoreObjectFactory.createStoreObject(StoreObjectEnum.DRINK, params);
            
        DrinksBrand drink = (DrinksBrand)ObjectRegistry.lookup(CloneableObjectEnum.DRINK);
        drink.initialize(params);
	    
	    System.out.println("ToString" +("Idx :"+idx+ "\nDrink "+drink));

	    item = new String("Quantity" + idx);
	    itemv = getValue(item);

	    cit = new DrinksStoreItem(db, Integer.parseInt(itemv));
	    return cit;
  }
  
  public void setItem(int it, StoreItem item){
    String  itn;
    int  itemv;
    String  its;
    DrinksBrand  cn;
    int idx = it + 1;

    cn = (DrinksBrand) item.getContent();
    itn = new String("Name" + idx);

    setValue(itn, cn.getName());

    itn = new String("Price" + idx);
    setValue(itn, String.valueOf(cn.getPrice()));

    itn = new String("Quantity" + idx);
    setValue(itn, String.valueOf(item.getQuantity()));
  }

}
